package com.undsf.chaldea.datacollect.fgowiki

import com.undsf.chaldea.entities.ServantMetadata
import com.undsf.chaldea.util.Converter
import com.undsf.chaldea.util.ServantClass

/**
 * Created by Arathi on 2017/8/22.
 */
data class Servant(
        var ID: String?,
        var NAME: String?,
        var NAME_JP: String?,
        var NAME_EN: String?,
        var PIC1: String?,
        var PIC2: String?,
        var PIC3: String?,
        var PIC4: String?,
        var PIC5: String?,
        var Avatar: String?,
        var STAR: String?,
        var CLASS: String?,
        var LV1_HP: String?,
        var LV1_ATK: String?,
        var LVMAX0_HP: String?,
        var LVMAX0_ATK: String?,
        var LVMAX1_HP: String?,
        var LVMAX1_ATK: String?,
        var LVMAX2_HP: String?,
        var LVMAX2_ATK: String?,
        var LVMAX3_HP: String?,
        var LVMAX3_ATK: String?,
        var LVMAX4_HP: String?,
        var LVMAX4_ATK: String?,
        var LV90_HP: String?,
        var LV90_ATK: String?,
        var LV100_HP: String?,
        var LV100_ATK: String?,
        var COST: String?,
        var ILLUST: String?,
        var CV: String?,
        var GLUTEN: String?,
        var DURABLE: String?,
        var AGILE: String?,
        var MAGIC: String?,
        var LUCKY: String?,
        var TREASURE: String?,
        var SKILL_R1: String?,
        var SKILL_P1: String?,
        var SKILL_L1: String?,
        var SKILL_C1: String?,
        var SKILL_E1: String?,
        var SKILL_R2: String?,
        var SKILL_P2: String?,
        var SKILL_L2: String?,
        var SKILL_C2: String?,
        var SKILL_E2: String?,
        var SKILL_R3: String?,
        var SKILL_P3: String?,
        var SKILL_L3: String?,
        var SKILL_C3: String?,
        var SKILL_E3: String?,
        var CSKILL_R1: String?,
        var CSKILL_P1: String?,
        var CSKILL_L1: String?,
        var CSKILL_E1: String?,
        var CSKILL_R2: String?,
        var CSKILL_P2: String?,
        var CSKILL_L2: String?,
        var CSKILL_E2: String?,
        var CSKILL_R3: String?,
        var CSKILL_P3: String?,
        var CSKILL_L3: String?,
        var CSKILL_E3: String?,
        var CSKILL_R4: String?,
        var CSKILL_P4: String?,
        var CSKILL_L4: String?,
        var CSKILL_E4: String?,
        var T_NAME: String?,
        var T_PROP: String?,
        var T_LEVEL: String?,
        var T_TYPE: String?,
        var T_EFFECT: String?,
        var CARD_BUSTER: String?,
        var CARD_ARTS: String?,
        var CARD_QUICK: String?,
        var INTRO1: String?,
        var INTRO2: String?,
        var INTRO3: String?,
        var INTRO4: String?,
        var INTRO5: String?,
        var INTRO6: String?,
        var INTRO7: String?,
        var Property: String?,
        var Camp: String?,
        var Crit: String?,
        var Death: String?,
        var CritPr: String?,
        var InitiativeNp: String?,
        var Passive: String?,
        var ArtHit: String?,
        var BusHit: String?,
        var QuiHit: String?,
        var EXHit: String?,
        var Height: String?,
        var Weight: String?,
        var Origin: String?,
        var Region: String?,
        var Attributes: String?,
        var Gender: String?,
        var T_Text_Arr: String?,
        var T_Num_Arr: String?,
        var S1LV: String?,
        var S2LV: String?,
        var S3LV: String?,
        var Skill_Name_Arr: String?,
        var Skill_Img_Arr: String?,
        var Skill_Border_Arr: String?,
        var Skill_Number_Arr: String?,
        var Skill_QP_Arr: String?,
        var Break_Name_Arr: String?,
        var Break_Img_Arr: String?,
        var Break_Border_Arr: String?,
        var Break_Number_Arr: String?,
        var Berak_QP_Arr: String?,
        var Circle: String?,
        var TdPointQ: String?,
        var TdPointA: String?,
        var TdPointB: String?,
        var TdPointEx: String?,
        var whereform: String?
) {
    fun toServantMetadata(): ServantMetadata {
        val converter = Converter.instance
        val meta = ServantMetadata(ID?.toInt() ?: 0)

        meta.name = this.NAME_JP
        meta.nameChinese = this.NAME
        meta.nameEnglish = this.NAME_EN
        meta.rank = this.STAR?.toInt() ?: 0
        val ClassName: String? = this.CLASS?.replace(" ", "_")
        meta.Class = ServantClass.valueOf(ClassName ?: "")
        //---
        meta.hpInit = this.LV1_HP?.toInt() ?: 0
        meta.atkInit = this.LV1_ATK?.toInt() ?: 0
        meta.cost = this.COST?.toInt() ?: 0
        meta.cardAmountQuick = this.CARD_QUICK?.toInt() ?: 0
        meta.cardAmountArts = this.CARD_ARTS?.toInt() ?: 0
        meta.cardAmountBuster = this.CARD_BUSTER?.toInt() ?: 0
        //---
        // TODO 技能相关信息
        //---
        meta.strength = this.GLUTEN
        meta.endurance = this.DURABLE
        meta.agility = this.AGILE
        meta.mana = this.MAGIC
        meta.luck = this.LUCKY
        meta.npRank = this.TREASURE
        meta.illustrator = this.ILLUST
        meta.castVoice = this.CV
        meta.characterDetail = this.INTRO1
        meta.storyPart1 = this.INTRO2
        meta.storyPart2 = this.INTRO3
        meta.storyPart3 = this.INTRO4
        meta.storyPart4 = this.INTRO5
        meta.storyPart5 = this.INTRO6
        meta.storyFinal = this.INTRO7
        //---
        meta.properties = mutableListOf()
        meta.camp = this.Camp
        // 由于 No.81 杰基尔&海德 的特例，在这里做特殊处理
        if (meta.id == 81) {
            val crit = this.Crit?.substring(0, this.Crit!!.indexOf(" "))
            val death = this.Death?.substring(0, this.Death!!.indexOf(" "))
            val critpr = this.CritPr?.substring(0, this.CritPr!!.indexOf(" "))
            meta.crit = converter.percentToDouble(crit ?: "0")
            meta.death = converter.percentToDouble(death ?: "0")
            meta.starAssign = critpr?.toInt() ?: 0
        }
        else {
            meta.crit = converter.percentToDouble(this.Crit ?: "0")
            meta.death = converter.percentToDouble(this.Death ?: "0")
            meta.starAssign = this.CritPr?.toInt() ?: 0
        }
        meta.npGainQuick = converter.percentToDouble(this.TdPointQ ?: "0")
        meta.npGainArts = converter.percentToDouble(this.TdPointA ?: "0")
        meta.npGainBuster = converter.percentToDouble(this.TdPointB ?: "0")
        meta.npGainEx = converter.percentToDouble(this.TdPointEx ?: "0")
        meta.npGainNp = converter.percentToDouble(this.InitiativeNp ?: "0")
        meta.npGainDamage = converter.percentToDouble(this.Passive ?: "0")
        meta.hitQuick = this.QuiHit?.toInt() ?: 0
        meta.hitArts = this.ArtHit?.toInt() ?: 0
        meta.hitBuster = this.BusHit?.toInt() ?: 0
        meta.hitEx = this.EXHit?.toInt() ?: 0

        return meta
    }
}
